package com.exp.controller;

import com.exp.dto.DeptPageQueryDTO;
import com.exp.dto.EmployeePageQueryDTO;
import com.exp.pojo.DeptInf;
import com.exp.pojo.EmployeeInf;
import com.exp.result.PageResult;
import com.exp.result.Result;
import com.exp.result.StatusCode;
import com.exp.service.EmployeeInfService;
import com.exp.utils.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工管理模块-why
 */
@RestController
@RequestMapping("/admin/employeeInf")
@Slf4j
public class EmployeeInfController {

    @Autowired
    private EmployeeInfService employeeInfService;

    /*
     * 员工查询-分页查询
     * 搜索条件：职位、性别、姓名、手机、身份证号、所属部门
     */
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody EmployeePageQueryDTO employeePageQueryDTO){
        System.out.println(employeePageQueryDTO);
        PageResult pageResult = employeeInfService.pageQuery(employeePageQueryDTO);
        return Result.success(StatusCode.SUCCESS, Message.PAGE_SUCCESS,pageResult);
    }

    /*
     * 添加员工
     * 输入：职位、性别、姓名、手机、身份证号、所属部门、学历、邮箱、电话、政治面貌、
     * qq号码、联系地址、邮政编码、出生日期、民族、所学专业、爱好、备注
     */
    @PostMapping("/add")
    public Result<EmployeeInf> save(@RequestBody EmployeeInf employeeInf){
        log.info("新增员工：{}",employeeInf);
        employeeInfService.save(employeeInf);
        return Result.success(StatusCode.SUCCESS,Message.SAVE_SUCCESS,employeeInf);
    }

    /*
     * 修改员工
     * 输入：职位、性别、姓名、手机、身份证号、所属部门、学历、邮箱、电话、政治面貌、
     * qq号码、联系地址、邮政编码、出生日期、民族、所学专业、爱好、备注
"job_inf.name""sex""name""phone""dept_inf.name""cardId""address""postCode""tel""qqNum"
"email""party""birthday""race""education""speciality""hobby""remark"
     */
    @PutMapping("/update")
    public Result update(@RequestBody EmployeeInf employeeInf){
        log.info("编辑员工信息：{}", employeeInf);
        employeeInfService.update(employeeInf);
        return Result.success(StatusCode.SUCCESS,Message.UPDATE_SUCCESS,employeeInf);
    }

    /*
    批量删除
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam List<Integer> ids) {
        employeeInfService.deleteBatch(ids);
        return Result.success(StatusCode.SUCCESS,Message.DELETE_SUCCESS,ids);
    }
}
